// pages/cart/cart.js
const http = require('../../http/index.js')
const api = require('../../api.js')
var app = new getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    cars: "",
    shop: true,
    sup: true,
    quan: true,
    ida: []
  },


  //加
  addCount: function (e) {
    var index = e.target.dataset.index;
    console.log("刚刚您点击了加+");
    var count = this.data.cars[index].quantity;
    // 商品总数量+1  
    if (count >= 1) {
      this.data.cars[index].quantity++;
    }
    // 将数值与状态写回  
    this.setData({
      cars: this.data.cars
    });
    //接口
    console.log('asdasdas', this.data.cars[index].goodsId)
    http(api.jia, "data",
      {
        customerId: 589,
        goodsId: this.data.cars[index].goodsId,
        goodsType: this.data.cars[index].goodsType,
        quantity: this.data.cars[index].quantity,
        shopId: 18,
        storeId: 56200,
        teminal: 2
      },
      "POST"
    ).then(res => {
      console.log("加接口", res)
    })
  },
  //减
  delCount: function (e) {
    var index = e.target.dataset.index;
    console.log("刚刚您点击了加一");
    var count = this.data.cars[index].quantity;
    // 商品总数量-1
    if (count > 1) {
      this.data.cars[index].quantity--;
    }
    // 将数值与状态写回  
    this.setData({
      cars: this.data.cars
    });
    http(api.jian, "data",
      {
        customerId: 589,
        goodsId: this.data.cars[index].goodsId,
        goodsType: this.data.cars[index].goodsType,
        quantity: this.data.cars[index].quantity,
        shopId: 18,
        storeId: 56200,
        teminal: 2
      },
      "POST"
    ).then(res => {
      console.log("加接口", res)
    })
  },
  //选中接口
  shopxuan(e) {
    console.log('；离开的佛南为分裂势力', e)
    let date = {
      customerId: 589,
      goodsIds: this.data.ida,
      shopId: 18,
      storeId: 56200,
      teminal: 2
    }
    http(api.shopxuan, "data", date, "POST").then(res => {
      console.log("选中", res)
      this.setData({
        shop: false,
        ida: e.currentTarget.dataset.list
      })
      console.log(this.data.ida)
    })
  },
  //未选
  shopwei(e) {

    let date = {
      customerId: 589,
      goodsIds: this.data.ida,
      shopId: 18,
      storeId: 56200,
      teminal: 2
    }
    http(api.shopbxuan, "data", date, "POST").then(res => {
      console.log("取消选中", res)
      this.setData({
        shop: true,
        ida: e.currentTarget.dataset.list
      })

    })
  },


  weix() {
    console.log("11111")
    this.setData({
      sup: !this.data.sup,
      shop: !this.data.shop
    })
  },
  //全选
  hequanbu() {
    this.setData({
      quan: false,
      shop: false,
      sup: false
    })

  },
  //全不选
  hequan() {
    this.setData({
      quan: true,
      shop: true,
      sup: true
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },
  jies() {
    wx.navigateTo({
      url: '/pages/jies/jies',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let data = {
      customerId: 589,
      shopId: 18,
      storeId: 56200,
      teminal: 2
    }
    http(api.xq, "", data, "POST").then(res => {
      console.log("11", res)
      this.setData({
        cars: res.data.result.selfOperatedCart.goodsCarQueryList[0].goodsList

      })
      app.globalData.jiesuan = this.data.cars
      console.log(this.data.cars);
      // console.log(this.data.cars[0].goodsList[0].addTime);
    })
    console.log(app.globalData.jiesuan);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})